<template>
  <a-card :bordered="false" class="card-area" height="100%" bottom="auto">
    <a-form :form="form">
      <a-form-item label='快递名称' v-bind="formItemLayout">
        <a-input v-decorator="['mca01',{rules: [
        { required: true, message: '快递名称不能为空'},
        {pattern:'^[\u4e00-\u9fa5\\\\w]+$',message:'请输入中文'},
        ]}]" />
      </a-form-item>
      <a-form-item label='英文编码' v-bind="formItemLayout">
        <a-input v-decorator="['mca02',{rules: [
        { required: true, message: '英文编码不能为空'},
        {pattern:'^[A-Z]+$',message:'请输入大写英文字母'},
        ]}]" />
      </a-form-item>
    </a-form>
    <div class="bootom-button" style="float:right;">
      <a-popconfirm title="确定放弃编辑？" @confirm="onClose" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="loading">提交</a-button>
    </div>
  </a-card>
</template>
<script>
const formItemLayout = {
  labelCol: {span: 6},
  wrapperCol: {span: 18}
}
export default {
  components: {},
  name: 'McaAdd',
  data () {
    return {
      loading: false,
      formItemLayout,
      form: this.$form.createForm(this)
    }
  },
  methods: {
    reset () {
      this.loading = false
      this.expandedKeys = this.checkedKeys = []
      this.form.resetFields()
    },
    onClose () {
      this.reset()
      this.$emit('close')
    },
    handleSubmit () {
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log(values)
          this.$api.freight.postMca(values).then(() => { // 提交所有mca字段
            this.$message.success('新增快递模板成功')
            this.reset()
            this.$router.push({path: `mca`})
          }).catch(() => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
